<template>
<div>
	<el-form ref="ruleForm" :rules="rules" :model="form" label-width="120px">
    <el-form-item label="角色名称" prop="roleName">
      <el-input v-model="form.roleName" />
    </el-form-item>
  </el-form>

  <div style="text-align: center;">
    <el-button type="primary" @click="onSubmit('ruleForm')">修改角色</el-button>
    <el-button @click="onCancel">关闭</el-button>
  </div>
</div>
</template>

<script>
export default {
  props: ['row'],
  data() {
    return {
      form: {},
      rules: {
        roleName: [
          { required: true, message: '请输入角色名称', trigger: 'blur' },
          { min: 2, max: 10, message: '长度在 2 到 10 个字符', trigger: 'blur' }
        ]
      }
    }
  },
  created() {
    this.getRoleList();
  },
  mounted() {

  },
  methods: {
    getRoleList(){
      this.form =this.row;
    },
    onSubmit(ruleForm) {
      this.$refs[ruleForm].validate((valid) => {
        if (valid) {
          this.$axios({
            url: '/system/role/update',
            method: 'post',
            data: this.form
          }).then((res) => {
            if(res.code == 200) {
              this.$message.success('修改角色成功！');
              this.$emit('refresh');
              this.$emit('closeDialog', false);
            }
          }).catch((err) => {
            this.$message(err)
          })
        } else {
          this.$message({
            message: '表单验证失败',
            type: 'warning'
          })
          return false;
        }
      });
    },
    onCancel() {
      this.$emit('closeDialog', false);
    },
  }
}
</script>

<style scoped>
.line{
  text-align: center;
}
</style>
